package com.example.javaairportflightanalysis.dao;

import com.example.javaairportflightanalysis.domin.check.Check;
import com.example.javaairportflightanalysis.domin.check.DfdlCheckAD;
import com.example.javaairportflightanalysis.domin.check.TransferCheckAD;
import com.example.javaairportflightanalysis.domin.merge.DfdlStatusDto;
import com.example.javaairportflightanalysis.domin.merge.TransferStatusDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CheckMapper {
    @Insert(" INSERT INTO zbtj.T_Check (MODIFIER, AUDITOR, CREATE_TIME, CHECK_TIME, STATUS,FLIGHT_TYPE, UUID)\n" +
            "    VALUES (#{modifier}, #{auditor}, #{createTime}, #{checkTime}, #{status},#{flightType}, #{uuid})")
    void insertCheck(Check check);
    @Update("UPDATE zbtj.T_Check SET " +
            "AUDITOR = #{auditor} , Status=#{status} ,CHECK_TIME=#{checkTime}" +
            "where uuid=#{uuid};")
    void updateCheckA(Check check);
    /**
     * 根据id查询审核的数据
     */
    @Select("select * from zbtj.T_Check where id=#{id}")
    Check selectById(Integer id);

    @Select("select dca.* from zbtj.Dfdl_Check_A dca join zbtj.T_Check tc" +
            " on tc.uuid=dca.uuid where tc.uuid=#{uuid}")
    DfdlCheckAD selectNewByUuidA(String uuid);

    @Select("select da.* from zbtj.Dfdl_A da join zbtj.T_Check tc" +
            " on tc.uuid=da.uuid where tc.uuid=#{uuid}")
    DfdlStatusDto selectOldByUuidA(String uuid);

    @Select("select dca.* from zbtj.Transfer_Check_A dca join zbtj.T_Check tc" +
            " on tc.uuid=dca.uuid where tc.uuid=#{uuid}")
    TransferCheckAD selectNewTransferByUuidA(String uuid);

    @Select("select da.* from zbtj.Transfer_A da join zbtj.T_Check tc" +
            " on tc.uuid=da.uuid where tc.uuid=#{uuid}")
    TransferStatusDto selectOldTransferByUuidA(String uuid);

    /**
     * 根据uuid查询D直达的数据
     */
    @Select("select dca.* from zbtj.Dfdl_Check_A dca join zbtj.T_Check tc" +
            " on tc.uuid=dca.uuid where tc.uuid=#{uuid}")
    Check selectByUuidCheckA(String uuid);
    @Select("select * from T_Check")
    List<Check> selectAllDate();

    @Update("UPDATE zbtj.Dfdl_A SET " +
            "DFLT_FLNO= #{dfltFlno},"   +
            "DFLT_AWCD = #{dfltAwcd}, " +
            "APCD = #{apcd}, " +
            "DTIME = #{dtime}," +
            "FPTT = #{fptt}, " +
            "FPLT = #{fplt}, " +
            "STATUS = #{status} where uuid=#{uuid};")
    void updateDfdlCheckA2(DfdlCheckAD dfdlCheckAD);
    @Update("UPDATE zbtj.Dfdl_Check_A SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateStatusA2(Integer status, String uuid);
    @Update("UPDATE zbtj.Dfdl_A SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateDfdlStatusA2(Integer status, String uuid);


    @Update("UPDATE zbtj.Transfer_A SET " +
            "dfltFlno= #{dfltFlno},"   +
            "dfltAwcd = #{dfltAwcd}, " +
            "transitApcd=#{transitApcd},"+
            "APCD = #{apcd}, " +
            "DTIME = #{dtime}," +
            "FPTT = #{fptt}, " +
            "FPLT = #{fplt}, " +
            "STATUS = #{status} where uuid=#{uuid};")
    void updateDfdlCheckA3(TransferCheckAD transferCheckAD);
    @Update("UPDATE zbtj.Transfer_Check_A SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateStatusA3(Integer status, String uuid);
    @Update("UPDATE zbtj.Transfer_A SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateTransferStatusA3(Integer status, String uuid);

    @Select("select dca.* from zbtj.Dfdl_Check_D dca join zbtj.T_Check tc" +
            " on tc.uuid=dca.uuid where tc.uuid=#{uuid}")
    DfdlCheckAD selectNewByUuidD(String uuid);

    @Select("select da.* from zbtj.Dfdl_D da join zbtj.T_Check tc" +
            " on tc.uuid=da.uuid where tc.uuid=#{uuid}")
    DfdlStatusDto selectOldByUuidD(String uuid);

    @Update("UPDATE zbtj.Dfdl_D SET " +
            "DFLT_FLNO= #{dfltFlno},"   +
            "DFLT_AWCD = #{dfltAwcd}, " +
            "APCD = #{apcd}, " +
            "DTIME = #{dtime}," +
            "FPTT = #{fptt}, " +
            "FPLT = #{fplt}, " +
            "STATUS = #{status} where uuid=#{uuid};")
    void updateDfdlCheckD2(DfdlCheckAD dfdlCheckAD);
    @Update("UPDATE zbtj.Dfdl_Check_D SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateStatusD2(Integer status, String uuid);
    @Update("UPDATE zbtj.Dfdl_D SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateDfdlStatusD2(Integer status, String uuid);
    @Select("select dca.* from zbtj.Transfer_Check_D dca join zbtj.T_Check tc" +
            " on tc.uuid=dca.uuid where tc.uuid=#{uuid}")
    TransferCheckAD selectNewTransferByUuidD(String uuid);
    @Select("select da.* from zbtj.Transfer_D da join zbtj.T_Check tc" +
            " on tc.uuid=da.uuid where tc.uuid=#{uuid}")
    TransferStatusDto selectOldTransferByUuidD(String uuid);


    @Update("UPDATE zbtj.Transfer_D SET " +
            "dfltFlno= #{dfltFlno},"   +
            "dfltAwcd = #{dfltAwcd}, " +
            "transitApcd=#{transitApcd},"+
            "APCD = #{apcd}, " +
            "DTIME = #{dtime}," +
            "FPTT = #{fptt}, " +
            "FPLT = #{fplt}, " +
            "STATUS = #{status} where uuid=#{uuid};")
    void updateDfdlCheckD3(TransferCheckAD transferCheckAD);
    @Update("UPDATE zbtj.Transfer_Check_D SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateStatusD3(Integer status, String uuid);
    @Update("UPDATE zbtj.Transfer_D SET " +
            "STATUS = #{status} " +
            "where uuid=#{uuid};")
    void updateTransferStatusD3(Integer status, String uuid);



}
